package com.ruoyi.project.bajiaostar.jbhWemember.service.impl;

import java.util.List;

import com.ruoyi.project.user.domain.TUser;
import com.ruoyi.project.user.service.ITUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.bajiaostar.jbhWemember.mapper.JbhWememberMapper;
import com.ruoyi.project.bajiaostar.jbhWemember.domain.JbhWemember;
import com.ruoyi.project.bajiaostar.jbhWemember.service.IJbhWememberService;
import com.ruoyi.common.utils.text.Convert;
import org.springframework.util.ObjectUtils;

/**
 * 会员信息Service业务层处理
 * 
 * @author 写烧糊
 * @date 2024-07-18
 */
@Service
public class JbhWememberServiceImpl implements IJbhWememberService 
{
    @Autowired
    private JbhWememberMapper jbhWememberMapper;
    @Autowired
    private ITUserService userService;

    /**
     * 查询会员信息
     * 
     * @param id 会员信息ID
     * @return 会员信息
     */
    @Override
    public JbhWemember selectJbhWememberById(Long id)
    {
        return jbhWememberMapper.selectJbhWememberById(id);
    }

    /**
     * 查询会员信息列表
     * 
     * @param jbhWemember 会员信息
     * @return 会员信息
     */
    @Override
    public List<JbhWemember> selectJbhWememberList(JbhWemember jbhWemember)
    {
        return jbhWememberMapper.selectJbhWememberList(jbhWemember);
    }

    /**
     * 新增会员信息
     * 
     * @param jbhWemember 会员信息
     * @return 结果
     */
    @Override
    public int insertJbhWemember(JbhWemember jbhWemember)
    {
        return jbhWememberMapper.insertJbhWemember(jbhWemember);
    }

    /**
     * 修改会员信息
     * 
     * @param jbhWemember 会员信息
     * @return 结果
     */
    @Override
    public int updateJbhWemember(JbhWemember jbhWemember)
    {
        if (jbhWemember.getIsVerify().equals(1)) {
            //检测是否注册
            TUser user=new TUser();
            user.setMobile(jbhWemember.getLoginName());
            List<TUser> list = userService.selectTUserList(user);
            if(!ObjectUtils.isEmpty(list)){
                throw new RuntimeException("账号名称已注册，请修改后重新审核");
            }
            TUser user1=new TUser();
            user1.setUserName(jbhWemember.getLoginName());
            user1.setPassword(jbhWemember.getLoginPassword());
            user1.setMobile(jbhWemember.getLoginName());
            user1.setChannel(1L);
            user1.setUserStatus(0);
            userService.insertTUser(user1);
        }
        return jbhWememberMapper.updateJbhWemember(jbhWemember);
    }

    /**
     * 删除会员信息对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteJbhWememberByIds(String ids)
    {
        return jbhWememberMapper.deleteJbhWememberByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除会员信息信息
     * 
     * @param id 会员信息ID
     * @return 结果
     */
    @Override
    public int deleteJbhWememberById(Long id)
    {
        return jbhWememberMapper.deleteJbhWememberById(id);
    }
}
